<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@page import="edu.ccut.saturn.component.SaturnData"%>
<html>
<head>
<%@ include file="/extjs/include/all.jsp"%>
<link href="${pageContext.request.contextPath}/edu.ccut.saturn.authority.impl/userModule/page/css/authority.css" rel="stylesheet" type="text/css">
<title>编辑用户信息</title>
<script type="text/javascript" src="${pageContext.request.contextPath}/extjs/js/validate.js">
</script>
</head>
<body>
</body>
</html>
<script>
Ext.onReady(function(){
 	Ext.QuickTips.init();  
	<%@ include file="jsp/store.jsp"%>
	function getUserResult(){
		Ext.Ajax.request({
		     method : 'POST',                             //发送方式.'POST'或'GET',一般是'POST'
		     url: '${pageContext.request.contextPath}/edu.ccut.saturn.authority.impl::/userModule/action/QueryUserByPK.action',                  //发送到页面
		     success:function(request){                   //发送成功的回调函数
		       	var myResult = Ext.util.JSON.decode(request.responseText);
		       	Ext.get("id").dom.value = myResult.resultuser.id;
		       	Ext.get("userid").dom.value = myResult.resultuser.id;
		       	Ext.get("usertype").dom.value = myResult.resultuser.usertype;
		       	Ext.get("password").dom.value = myResult.resultuser.password;
		       	Ext.get("user_position_show").dom.value = myResult.resultuser.position_dict; 
		       	Ext.get("username").dom.value = myResult.resultuser.username;
		       	Ext.get("descn").dom.value = myResult.resultuser.descn;
		       	Ext.get("dept_id").dom.value = myResult.resultuser.dept_id;
		       	Ext.get("position").dom.value = myResult.resultuser.position;
		        Ext.get("dept_id_show").dom.value = '<%=request.getParameter("dept_name")%>';  
		     },
		     failure:function(){                          //发送失败的回调函数
		       Ext.Msg.alert("错误", "与后台联系的时候出现了问题");
		     },
		     params:{
		     		id:'<%=request.getParameter("id")%>'
		     } 
     	});
    }
    getUserResult();
	//--------------------------------------------------------------------------------------------
	//						修改用户信息表单
	//
	//
	//
	//
	//--------------------------------------------------------------------------------------------
	
	var editUser = new Ext.FormPanel({
	    labelWidth: 75,
	    id:'editUser',
	    frame:true,
	    title: '编辑用户信息',
	    bodyStyle:'padding:5px 5px 0',
	    width: 350,
	    defaults: {width: 230},
	    defaultType: 'textfield',
		reader: new Ext.data.JsonReader({
			
		}),	
	    items: [ {
	            name: 'id',
	            id: 'id',
	            inputType:'hidden',
	            hidden:true
	        },{
	            name: 'usertype',
	            id: 'usertype',
	            inputType:'hidden',
	            hidden:true
	        },{
	            name: 'password',
	            id: 'password',
	            inputType:'hidden',
	            hidden:true
	        },{
	        	fieldLabel: '登录名',
	            name: 'userid',
	            id: 'userid',
	            disabled:true
	        },{
	            fieldLabel: '姓名',
	            name: 'username',
	            id: 'username',
	            maxLength:10,
	            allowBlank:false,
	            blankText:'姓名不可为空',
	            vtype: 'isNumberAlphaUnderlineChinese'
	        },{
	            xtype:'combo',
				fieldLabel: '职位',
                name: 'user_position_show',
                id: 'user_position_show',
                store: qx_position_store,
		        displayField:'value',
		        valueField :'key',  
		        hiddenName: 'position' ,
		        typeAhead: true,
		        mode: 'local',
		        forceSelection: true,
		        triggerAction: 'all',
		        emptyText:'请选择职位...',
		        selectOnFocus:true,
		        editable: false,
		        allowBlank:false,
	            blankText:'职位不可为空'
	        },{
	            xtype:'combo',
                fieldLabel: '机构',
                name: 'dept_id_show',
                id:'dept_id_show',
                store: dept_store,
		        displayField:'value',
		        valueField :'key',  
		        hiddenName: 'dept_id' ,
		        typeAhead: true,
		        mode: 'local',
		        forceSelection: true,
		        triggerAction: 'all',
		        emptyText:'请选择机构...',
		        selectOnFocus:true,
		        editable: false,
		        allowBlank:false,
	            blankText:'机构不可为空'
	        },{
	        	xtype:'textarea',
	            fieldLabel: '描述',
	            name: 'descn',
	            id: 'descn',
	            vtype: 'isNumberAlphaUnderlineChineseSpaceMaxLength200'
	        }
	    ]
	});
	

		
	//--------------------------------------------------------------------------------------------
	//						修改用户
	//
	//
	//
	//
	//--------------------------------------------------------------------------------------------
					
     var win = new Ext.Window({
         layout      : 'fit',
         width       : 500,
         height      : 300,
         plain       : true,
         animEl: 'result',
         closable: false,
         items: [editUser],
         buttons: [{
             text     : '修改',
             handler  : function(){
                if(editUser.form.isValid()){
                		editUser.form.submit({					                		
                			url: '${pageContext.request.contextPath}/edu.ccut.saturn.authority.impl::/userModule/action/Update.action', 
		               		success : function(form, action) {
		               			var myResult = Ext.util.JSON.decode(action.response.responseText);
	               				if(myResult.result > 0){
	               					Ext.MessageBox.show({
	               				 		title: '修改成功',
	                                    msg: '恭喜您，修改信息成功！',
	                                    width:200,
	                                    buttons: Ext.MessageBox.OK,
	                                    fn: function(btn) {
									         window.location = '${pageContext.request.contextPath}/edu.ccut.saturn.authority.impl/userModule/page/userList.jsp';
									    }
	                                 });
								  } else {
									  	Ext.MessageBox.show({
		                                    title: '修改失败',
		                                    msg: '对不起，修改信息失败！',
		                                    buttons: Ext.MessageBox.OK,
		                                    icon: Ext.MessageBox.ERROR
	                                	});
								  }
		                    },
                      	    failure: function(form, action) {
		                       	Ext.MessageBox.show({
		                                   title: '修改失败',
		                                   msg: '对不起，修改信息失败！',
		                                   buttons: Ext.MessageBox.OK,
		                                   icon: Ext.MessageBox.ERROR
			                                	});
	                        },
              				waitMsg:'正在修改用户信息，请稍后...'
               			});
                	}else{
                		Ext.MessageBox.alert('警告','对不起，您的信息有误！')
                	}
                }
            },{
                text     : '返回',
                handler  : function(){
                    window.location = 'userList.jsp'
                    }
           },{
                text     : '重置',         
                handler  : function(){
                    getUserResult();
                }
            }]
       });
       win.show();
       document.getElementById('username').maxLength = 10;
	   document.getElementById('descn').maxLength = 30;
});
</script>
